#include "channel.hpp"

int main()
{
    // 创建进程池
    My_Process_Pool::ProcessPool myprocess;
    My_Process_Pool::Channel chan[5];
    // new 进程
    myprocess.new_back(&chan[0]);
    myprocess.new_back(&chan[1]);
    myprocess.new_back(&chan[2]);
    myprocess.new_back(&chan[3]);
    myprocess.new_back(&chan[4]);
    myprocess.print();
    sleep(1);

    // 生成任务
    int myworks[] = {0, 2, 2, 2, 4, 3, 3, 3, 5, 5, 5, 2, 2, 2, 3, 4, 3, 3, 3, 1};

    // 派发任务
    int flag = 0;

    int len = sizeof(myworks) / sizeof(myworks[0]);
    for (int i = 0; i < len; i++)
    {
        if (flag >= myprocess.size())
        {
            flag = 0;
        }
        // std::cout << "flsg " << flag << std::endl;
        myprocess.send(flag, myworks[i]);
        flag++;
        sleep(1);
    }
    int num = myprocess.size();
    while (num--)
    {
        std::cout << "进程结束 " << num << std::endl;
        myprocess.send(num, 20);
        sleep(1);
    }

    return 0;
}